/*
 * @Author: 姚潘涛
 * @Date: 2024-04-08 15:18:03
 * @LastEditors: 姚潘涛
 * @LastEditTime: 2024-10-10 15:02:34
 * @Description:
 *
 * Copyright (c) 2024 by pandaman, All Rights Reserved.
 */
#pragma once

#include "opencv2/opencv.hpp"
#include "xict_common/log/log.h"
#include <memory>
#include <string>

namespace xict_cpp {
    namespace core {
        namespace stage {
            /// \brief Stage is the base class of all stages in the pipeline.
            /// \details It provides the basic unit for the pipeline.
            /// The pipeline is a series of stages, and each stage
            /// is responsible for a specific task.
            class Stage {
            public:
                // Key functions

                /// \brief Default constructor.
                Stage() = default;
                /// \brief Default destructor.
                virtual ~Stage() = default;

            public:
                // Key functions

                /// \brief Initialize the stage with the given parameters.
                /// \return True if the initialization is successful, false
                /// otherwise.
                virtual bool Init() = 0;
                /// \brief Process the data frame.
                /// \param data The data frame to be processed.
                /// \return True if the processing is successful, false
                /// otherwise.
                virtual bool Process() = 0;

            public:
                // Getters

                /// \brief Check if the stage is enabled.
                /// \return True if the stage is enabled, otherwise false.
                virtual bool IsEnabled() const {
                    return enabled_;
                }
                /// \brief Get the name of the stage.
                /// \return The name of the stage.
                virtual std::string Name() const = 0;

            public:
                // Setters

                /// \brief Set the enabled flag of the stage.
                /// \param enabled The enabled flag of the stage.
                virtual void SetEnabled(bool enabled) {
                    AINFO_F("{} is set to {}", Name(),
                            enabled ? "enabled" : "disabled");
                    enabled_ = enabled;
                }

            protected:
                /// \brief Internal initialization function for the stage.
                /// \return True if the initialization is successful, false
                /// otherwise.
                virtual bool Initialize() = 0;
                /// \brief Reset the stage.
                virtual void Reset() = 0;

            protected:
                /// \brief Flag to indicate if the stage is enabled.
                bool enabled_ = false;
            };
            using StagePtr      = std::shared_ptr<Stage>;
            using StageConstPtr = std::shared_ptr<const Stage>;
        }   // namespace stage
    }       // namespace core
}   // namespace xict_cpp